package com.prime_factor_gen;

import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Scanner;

public class PrimeFactorGen {
    static Scanner userInput = new Scanner(System.in);

    public static void main(String[] args)
    {
        prompt();
    }

    public static void prompt()
    {
        int a=0;
        try
        {
            System.out.println("Enter an integer to receive a list of prime factors:");
            a = userInput.nextInt();
        } catch(InputMismatchException exception)
        {
            System.out.println("This is not an integer");
        }
        for (int prime_factor: generate(a)){
            System.out.print(prime_factor + " ");
        }
    }

    public static ArrayList<Integer> generate(int n)
    {
        ArrayList<Integer> prime_factors = new ArrayList<Integer>();
        for (int factor: factors(n)){
            if (factors(factor).size() == 2 ){
                prime_factors.add(factor);
            }
        }
        return prime_factors;
    }

    public static ArrayList<Integer> factors(int n)
    {
        ArrayList<Integer> factors = new ArrayList<Integer>();
        for (int x = 1; x <= n; x++){
            if (n % x == 0){
                factors.add(x);
            }
        }
        return factors;
    }
}
